<template>
	<view class="userLayout pageBg" v-if="userInfo">
		<view :style="{paddingTop: getNavBarHeight() + 'px'}"></view>
		<view class="userInfo">
			<view class="avatar">
				<image src="../../static/images/xxmLogo.png" mode="aspectFill"></image>
			</view>
			<view class="ip">{{userInfo.IP}}</view>
			<view class="address">
				来自于: {{userInfo.address.city || userInfo.address.province || userInfo.address.country}}
			</view>
		</view>

		<view class="section">
			<navigator url="/pages/classList/classList?name=我的下载&type=download">
				<user-item text='我的下载' :count="userInfo.downloadSize">
					<template #icon>
						<uni-icons type="download-filled" size="20"></uni-icons>
					</template>
				</user-item>
			</navigator>

			<navigator url="/pages/classList/classList?name=我的评分&type=score">
				<user-item text='我的评分' :count="userInfo.scoreSize">
					<template #icon>
						<uni-icons type="star-filled" size="20"></uni-icons>
					</template>
				</user-item>
			</navigator>

			<user-item class="last-item" text='联系客服' :showContact="true">
				<template #icon>
					<uni-icons type="chatboxes-filled" size="20"></uni-icons>
				</template>
			</user-item>
		</view>
		<view class="section">
			<navigator url="/pages/notice/detail?id=653507c6466d417a3718e94b&name=订阅更新">
				<user-item text='订阅更新'>
					<template #icon>
						<uni-icons type="notification-filled" size="20"></uni-icons>
					</template>
				</user-item>
			</navigator>
			
			<navigator url="/pages/notice/detail?id=6536358ce0ec19c8d67fbe82&name=常见问题">
				<user-item class="last-item" text='常见问题'>
					<template #icon>
						<uni-icons type="flag-filled" size="20"></uni-icons>
					</template>
				</user-item>
			</navigator>

		</view>
	</view>
	<view class="loadingLayout" v-else>
		<view :style="{paddingTop: getNavBarHeight() + 'px'}"></view>
		<uni-load-more status="loading"></uni-load-more>
	</view>
</template>

<script setup>
	import {
		getNavBarHeight
	} from '@/utils/system.js'
	import {
		apiUserInfo
	} from '@/api/api.js'
	import {
		ref
	} from 'vue';

	const userInfo = ref(null)
	const getUserInfo = async () => {
		const res = await apiUserInfo()
		userInfo.value = res.data
		console.log('userInfo', userInfo.value)
	}
	getUserInfo()
</script>

<style lang="scss" scoped>
	.userLayout {
		.userInfo {
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			padding: 50rpx 0;

			.avatar {
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.ip {
				font-size: 44rpx;
				color: #333;
				padding: 20rpx 0 5rpx;
			}

			.address {
				font-size: 28rpx;
				color: #aaa;
			}
		}

		.section {
			width: 690rpx;
			margin: 50rpx auto;
			border: 1rpx solid #eee;
			border-radius: 10rpx;
			box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);

			:deep() {
				.uni-icons {
					color: $brand-theme-color !important;
				}
			}

			.last-item {
				border-bottom: none;
			}
		}
	}
</style>